﻿@model cloudscribe.Core.IdentityServerIntegration.Models.ApiListViewModel
@using cloudscribe.Core.IdentityServerIntegration
@using cloudscribe.Web.Pagination
@using Microsoft.Extensions.Localization
@addTagHelper "*, cloudscribe.Web.Pagination"
@inject IStringLocalizer<CloudscribeIds4Resources> sr
@{
    var rIndex = 0;
}
<div class="row">
    <div class="col-md-10 col-md-push-2">
        <h2>@ViewData["Title"]</h2>
        <p>@sr["API Resources identify web APIs (also called resource servers). To get access tokens for APIs, you need to register them."]</p>
        <p>To learn more about scopes see the <a href="https://identityserver4.readthedocs.io/en/release/topics/resources.html#defining-api-resources">IdentityServer Documentation</a></p>
        <div>
            <table class="table table-striped">
                <tr>
                    <th>
                        <a class="btn btn-xs btn-default" asp-action="EditApiResource" asp-controller="ApiResource"
                           asp-route-siteId="@Model.SiteId">@sr["New Api Resource"]</a>
                    </th>
                    <th>
                        @sr["Name"]
                    </th>
                    <th>
                        @sr["Display Name"]
                    </th>
                    <th>
                        @sr["Description"]
                    </th>
                    <th>
                        @sr["Enabled"]
                    </th>
                </tr>
                @foreach (var s in Model.Apis.Data)
                {
                    <tr>
                        <td>
                            <a class="btn btn-xs btn-default" asp-action="EditApiResource" asp-controller="ApiResource"
                               asp-route-siteId="@Model.SiteId"
                               asp-route-apiname="@s.Name">@sr["Edit"]</a>
                            <button type="button" class="btn btn-danger btn-xs" data-toggle="modal" data-target="@("#confirmDeleteResourceModal" + rIndex)">
                                @sr["Delete"]
                            </button>
                            <form asp-controller="ApiResource" asp-action="DeleteApiResource">
                                <input name="SiteId" value="@Model.SiteId" type="hidden" />
                                <input name="ApiName" value="@s.Name" type="hidden" />
                                <div class="modal fade" id="@("confirmDeleteResourceModal" + rIndex)" tabindex="-1" role="dialog" aria-labelledby="@("confirmDeleteResourceHeading" + rIndex)">
                                    <div class="modal-dialog modal-sm" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal" aria-label='@sr["Close"]'><span aria-hidden="true">&times;</span></button>
                                                <h4 class="modal-title" id="@("confirmDeleteResourceHeading" + rIndex)">@sr["Confirm Delete"]</h4>
                                            </div>
                                            <div class="modal-body">
                                                @string.Format(sr["Are you sure you want to delete the API Resource {0}?"], s.Name)
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">@sr["Cancel"]</button>
                                                <input type="submit" value='@sr["Delete"]' class="btn btn-danger btn-ok" />
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </td>

                        <td>
                            @Html.DisplayFor(modelItem => s.Name)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => s.DisplayName)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => s.Description)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => s.Enabled)
                        </td>
                    </tr>
                    {
                        rIndex += 1;
                    }
                }
            </table>
            <div>
                <cs-pager asp-action="Index" asp-controller="ApiResource"
                          asp-route-siteId="@Model.SiteId"
                          asp-route-pagesize="@Model.Apis.PageSize"
                          cs-paging-pagenumber="@Model.Apis.PageNumber"
                          cs-paging-totalitems="@Model.Apis.TotalItems"
                          cs-first-page-title='@sr["First Page"]'
                          cs-last-page-title='@sr["Last Page"]'
                          cs-previous-page-title='@sr["Previous page"]'
                          cs-next-page-title='@sr["Next page"]'></cs-pager>
            </div>
        </div>
    </div>
    <div class="col-md-2 col-md-pull-10">
        @await Component.InvokeAsync("Navigation", new { viewName = "SideNavAlt1", filterName = NamedNavigationFilters.ParentTree, startingNodeKey = "SiteAdmin" })
    </div>
</div>

@section scripts {
    @{ await Html.RenderPartialAsync("_SideMenuScriptsPartial"); }

}